<template>
  <div class="shouye">
    <div class="tabbar">
      <van-tabs ref="tabs" v-model="active" @click="tiao">
        <router-view></router-view>
        <van-tab
          v-for="(item, index) in tabbar"
          :title="item.title"
          :key="index"
          :name="index+1"
        >
        </van-tab>
        <div class="tableft">
      
      <van-cell class="vancell"  @click="showPopup"><img src="../assets/分类.png" alt="" ></van-cell>
      <van-popup v-model="show" position="bottom" :style="{ height: '60%' }">
        <div class="toptitle">
          <p>分类</p>
        </div>
         
         <div class="topcentent">
           <div @click="dian(index+1)"  class="item" :class="{activecolor: activeindex===index}"  v-for="(item,index) in tabbar" :key="index">{{item.title}}</div>
         </div>
      </van-popup >
    </div>
    </van-tabs>
    </div>

    
  </div>
</template>

<script>
export default {
  name: "shouye",
  created() {
    this.gettabbar();
    this.$router.push({name:'1'})
  },
  data() {
    return {
      active: 1,
      activeindex:0,

      indexx:'',
      tabbar: [],
       show: false,
    };
  },
  methods: {
     showPopup() {
      this.show = true;
    },
    //跳转相对于的路由
    tiao(name){ 
     
      this.activeindex=name-1
      this.$router.push({name:name})
      
    },
    //分类跳转
    dian(index){
      this.active=index
      this.$router.push({name:index})
      this.show = false;
        if (this.activeindex === index-1) {
        return;
      }
      this.activeindex = index-1;
      this.indexx=index
     
    },
    gettabbar() {
      this.axios({
        method: "get",
        url: "https://apis.netstart.cn/xpc/home/config",
        params: {},
      }).then((result) => {
        if (result.status === 200) {
         
          for (let i = 0; i < result.data.data.tab.length; i++) {
            if (
              result.data.data.tab[i].title == "关注" ||
              result.data.data.tab[i].title == "入场必看" ||
              result.data.data.tab[i].title == "广告" 
            ) {
              result;
            } else {
              this.tabbar.push(result.data.data.tab[i]);
            }
          }
          
        }
      });
    },
  },
};
</script>

<style lang="less" scoped>
.shouye{
  width: 100%;
}
.tabbar{
  width: 100%;
  height: 50px;
  position: fixed;
  top:0;
  left: 0;
  right: 0;
  bottom: 0;

      
}
 .tableft{
         position: absolute;
         left: 85%;
         top:3px;
         width: 12%;
         height: 40px;
         .van-cell { 
           width: 50px;
           height: 40px;
           margin-left: 10px;
           margin-top: -2px;
         }
         .toptitle{
           width: 100%;
           height: 35px;
           font-size: 18px;
           p:nth-child(1){
             margin-left: 45%;

           }
           p:nth-child(2){
             font-size: 15px;
             font-weight: bold;
             margin-left: 35px;
           }
         }
         .topcentent{
           width: 90%;
           height: 250px;
           margin-left: 15px;
           margin-top: 20px;
           display: flex;
           
           flex-wrap: wrap;
           .item{
             width: 28%;
             height: 30px;
             text-align: center;
             line-height: 30px;
             margin-left: 15px;
             background-color: #ddd;
           }
         }
         img:nth-child(1){
           width: 20px;
           height: 20px;
           margin-left: 10%;
         }
         img:nth-child(2){
           width: 17px;
           height: 17px;
           margin-left: 20%;
         }
  }
  .activecolor{
    color: red;
  }

</style>